package com.lh.pospi.x_store.utils;

import java.text.DecimalFormat;
import java.util.Random;

public class Util {
    public static DecimalFormat DOUBLE_FORMAT = new DecimalFormat("#######.00");
    public static String getRandomString(int length) { //length表示生成字符串的长度
        String base = "abcdefghijklmnopqrstuvwxyz123456789";   //生成字符串从此序列中取
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static Double formatNum(Double val) {
        if (val == null) {
            return 0.00;
        } else {
            return Double.valueOf(DOUBLE_FORMAT.format(val));
        }
    }
}
